package com.example.javaeekeshe.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 化粪池堵塞的凶手
 */
@Configuration
public class MVCConfig implements WebMvcConfigurer {

    /**
     * 赋值文件读写权限
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/img/**").addResourceLocations("file:D://Learn/IDEAproject/javaEEKeShe/src/main/resources/static/img/");
    }

    //视图跳转
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/login.html").setViewName("login");
        registry.addViewController("/repassword").setViewName("resetPassword");
        registry.addViewController("/admin/login").setViewName("/admin/login");
        registry.addViewController("/admin/index").setViewName("/admin/index/index");
        registry.addViewController("/account/add").setViewName("/user/address/add");

    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns("/**").excludePathPatterns("/layui/**","/css/**","/js/**","/img/**","resetPassword",
                "/","/index","/index.html","/xiangqing/*","/xiangqing.html","/login.html","/login","/resetPassword","/resetPassword.html","/user/**","/repassword",
                "/repassword.html","/admin/login","/admin/login/**","/admin/login.html");
    }
}

